<?php

namespace app\admin\controller;

use app\admin\service\MenuService;
use support\Request;

class MenuController extends Curd
{
    /**
     * 菜单列表
     */
    public function index()
    {
        if (request()->isAjax()) {
            $menuService = new MenuService();
            return sparkSuccess($menuService->getMenuTree());
        }
        return view('menu/index');
    }

    /**
     * 新增菜单
     */
    public function add()
    {
        if (request()->isAjaxPost()) {
            $menuService = new MenuService();
            return sparkSuccess($menuService->addMenu(request()->post()));
        }
    }

    /**
     * 编辑菜单
     */
    public function edit()
    {
        if (request()->isAjaxPost()) {

            $menuService = new MenuService();
            return sparkSuccess($menuService->editMenu(request()->post()));
        }
    }

    /**
     * 删除菜单
     */
    public function del()
    {
        $menuService = new MenuService();
        return sparkSuccess($menuService->delMenu(request()->input('id')));
    }

}